home *** CD-ROM | disk | FTP | other *** search
/ Software Explosion / Software Explosion (Fore-Matt Home Computing)(1996).iso / games / workbench / lander_2 / source / cleanup.c < prev    next >
C/C++ Source or Header  |  1996-01-01  |  631b  |  39 lines

  1. #include <exec/memory.h>
  2.  
  3. struct _clean {
  4.     int (*function)();
  5.     char *name;
  6.     struct _clean *next;
  7. } *cleanlist = NULL;
  8.  
  9. add_cleanup(function, name)
  10. int (*function)();
  11. {
  12.     struct _clean *ptr;
  13.  
  14.     ptr = AllocMem(sizeof(struct _clean), MEMF_PUBLIC);
  15.     if(!ptr)
  16.         return 0;
  17.     ptr->function = function;
  18.     ptr->name = name;
  19.     ptr->next = cleanlist;
  20.     cleanlist = ptr;
  21. }
  22.  
  23. cleanup(debug)
  24. int debug;
  25. {
  26.     struct _clean *ptr;
  27.     int (*f)();
  28.  
  29.     while(cleanlist) {
  30.         ptr = cleanlist;
  31.         cleanlist = cleanlist->next;
  32.         f = ptr->function;
  33.         if(debug == 1)
  34.             printf("Cleanup: removing '%s'\n", ptr->name);
  35.         FreeMem(ptr, sizeof(struct _clean));
  36.         (*f)();
  37.     }
  38. }
  39.